package com.xr.miniprogram.controller.service;


import com.xr.common.core.controller.BaseController;
import com.xr.common.core.domain.AjaxResult;
import com.xr.miniprogram.domain.MiniProgramService;
import com.xr.miniprogram.domain.vo.MiniProgramServiceVO;
import com.xr.miniprogram.service.IMiniProgramServiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api("小程序服务详情控制")
@RestController
@RequestMapping("/miniprogram/service")
public class MiniProgramServiceController extends BaseController {
    @Resource
    public IMiniProgramServiceService miniProgramServiceService;

    /**
     * 根据服务菜单编号获取服务详情
     * @param menuId
     * @return
     */
    @ApiOperation("根据服务菜单id获取服务详情")
    @GetMapping(value = "/get")
    public AjaxResult get(@ApiParam(value = "菜单id", required = true) @RequestParam("menuId") Long menuId)
    {
        MiniProgramService service = miniProgramServiceService.getServiceByMenuId(menuId);
        if(service != null){
            MiniProgramServiceVO miniProgramServiceVO = MiniProgramServiceVO.toMiniProgramServiceVO(service);
            miniProgramServiceVO.setServiceSum(miniProgramServiceService.serviceOrderNumById(service.getServiceId()));
            return success(miniProgramServiceVO);
        }
        else return success((Object) null);
    }

    /**
     * 根据服务id获取服务详情
     * @param serviceId
     * @return
     */
    @ApiOperation("根据服务id获取服务详情")
    @GetMapping(value = "/getById")
    public AjaxResult getById(@ApiParam(value = "服务id", required = true) @RequestParam("serviceId") Long serviceId)
    {
        MiniProgramService service = miniProgramServiceService.getServiceByServiceId(serviceId);
        if (service!=null) {
            MiniProgramServiceVO miniProgramServiceVO = MiniProgramServiceVO.toMiniProgramServiceVO(service);
            miniProgramServiceVO.setServiceSum(miniProgramServiceService.serviceOrderNumById(service.getServiceId()));
            return success(miniProgramServiceVO);
        }else {
            return success((Object) null);
        }
    }
}
